package com.dense.kuiniu.shelfcard.view;

import android.graphics.Rect;
import android.view.View;

import org.jetbrains.annotations.NotNull;

import androidx.recyclerview.widget.RecyclerView;

/**
 * @author Administrator
 * @date 2020/8/11
 */
public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int space;  //位移间距

    public SpaceItemDecoration(int space) {
        this.space = space;
    }

    @Override
    public void getItemOffsets(@NotNull Rect outRect, @NotNull View view, RecyclerView parent, @NotNull RecyclerView.State state) {
        if (parent.getChildAdapterPosition(view) % 2 == 0) {
            outRect.left = 0; //第一列左边贴边
        } else {
            outRect.left = space;//第二列移动一个位移间距
        }

        if (parent.getChildAdapterPosition(view) >= 2) {
            outRect.top = space;
        } else {
            outRect.top = 0;
        }
    }

}